{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "#处理的数据样本结构是\n",
    "#  数据集/类文件夹/人文件夹/10个视频\n",
    "import os\n",
    "import shutil\n",
    "ori_basepath=\"/samba/HDD/AAAAA_CANGKU_DATASET/data_elec20170510/\"\n",
    "work_basepath=\"/samba/HDD/dataset_elec20170510/\"\n",
    "classlist=[]\n",
    "_classlist=os.listdir(ori_basepath)\n",
    "for item in _classlist:\n",
    "    classlist.append(os.path.join(basepath,item))\n",
    "classlist.sort()   #得到每个类的路径\n",
    "class_num=len(classlist)\n",
    "#############################################\n",
    "#对原始数据中的每一类中的所有视频进行标号，并存到/samba/HDD/dataset_elec20170510/下\n",
    "for class_ in range(len(classlist)):\n",
    "    clip_list=[]\n",
    "    #print(\"%sclass_%02d\" % (work_basepath,class_+1))\n",
    "    class_dir=\"%sclass_%02d/\" % (work_basepath,class_+1)\n",
    "    if os.path.exists(class_dir)==False:\n",
    "        os.mkdir(class_dir)        \n",
    "    filename_seq=0   #同一类中每个视频样本的序号\n",
    "    pplist=[]\n",
    "    _pplist=os.listdir(classlist[class_])\n",
    "    for item in _pplist:\n",
    "        pplist.append(os.path.join(classlist[class_],item))\n",
    "    pplist.sort()    #得到每个类下每个人的路径\n",
    "    #############################################\n",
    "    for pp in range(len(pplist)):\n",
    "        videolist=[]\n",
    "        _videolist=os.listdir(pplist[pp])\n",
    "        for item in _videolist:\n",
    "            videolist.append(os.path.join(pplist[pp],item))\n",
    "        videolist.sort()    #得到每个类下每个人的视频\n",
    "        #############################################\n",
    "        videonum_check=0\n",
    "        for video in videolist:\n",
    "            filename_seq += 1\n",
    "            videonum_check += 1\n",
    "            newname=pplist[pp]+\"/\"+str(\"%03d\" % filename_seq)+\".avi\"\n",
    "            #print(video,\"==>\",newname)\n",
    "            os.rename(video,newname)\n",
    "            #print(newname,\"  copy to   \",newname.replace(ori_basepath,work_basepath))\n",
    "            workavi=\"%s%03d.avi\" %(class_dir,filename_seq)\n",
    "            print(newname,\"--->\",workavi)\n",
    "            shutil.copyfile(newname,workavi)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "scrolled": false
   },
   "source": [
    "下一步，数据随机打乱"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/home/wjj/2333.xxx'"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fid=open(\"test.xxx\",'w')\n",
    "\n",
    "fid.writelines(\"sss\")\n",
    "fid.close()\n",
    "os.rename(\"test.xxx\",\"xxx.xxx\")\n",
    "shutil.(\"xxx.xxx\",\"/home/wjj/2333.xxx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['dataset_pysvmtest',\n",
       " 'Desktop',\n",
       " '.mozilla',\n",
       " 'core',\n",
       " '2333.xxx',\n",
       " '.profile',\n",
       " 'local_install',\n",
       " 'c3d-tensorflow2-master',\n",
       " '.Xauthority',\n",
       " '.bash_logout',\n",
       " 'Downloads',\n",
       " '.ssh',\n",
       " 'TEST',\n",
       " '.bashrc',\n",
       " '.pip',\n",
       " 'C3D-tensorflow-hand',\n",
       " '可视化小猫.ipynb',\n",
       " '.gconf',\n",
       " 'Templates',\n",
       " '.python_history',\n",
       " '.viminfo',\n",
       " 'xstartup_bk',\n",
       " '.thumbnails',\n",
       " '.gnome2',\n",
       " 'caffe',\n",
       " '.xsession',\n",
       " '.vim',\n",
       " '.zcompdump',\n",
       " 'examples.desktop',\n",
       " '.cache',\n",
       " '.xsession-errors',\n",
       " '.cmake',\n",
       " 'wangyu',\n",
       " '.jupyter',\n",
       " 'single_label.txt',\n",
       " 'output_pytest',\n",
       " 'matlabworkspace',\n",
       " '.bash_history',\n",
       " '.config',\n",
       " '.gitconfig',\n",
       " 'deep-soli',\n",
       " '.bashrc-anaconda3.bak',\n",
       " 'Pictures',\n",
       " '.ipynb_checkpoints',\n",
       " '.vimrc',\n",
       " 'HDD',\n",
       " '.java',\n",
       " '.luarocks',\n",
       " '.ipython',\n",
       " '.theano',\n",
       " '.gstreamer-0.10',\n",
       " 'tencent',\n",
       " 'C3D-tensorflow-elec',\n",
       " 'lisa-caffe-public-lstm_video_deploy',\n",
       " 'xstartup',\n",
       " 'zzd',\n",
       " '.continuum',\n",
       " '.luahistory',\n",
       " '.JxBrowser',\n",
       " '.vnc',\n",
       " '.dbus',\n",
       " '.felix',\n",
       " '.subversion',\n",
       " '.conda',\n",
       " '.lesshst',\n",
       " '.distlib',\n",
       " '.nv',\n",
       " 'anaconda3',\n",
       " '.gnuplot-wxt',\n",
       " 'C3D',\n",
       " '.condarc',\n",
       " 'C3D-tensorflow-UCF101',\n",
       " '.local',\n",
       " '.ICEauthority',\n",
       " '.matlab',\n",
       " 'pyml',\n",
       " 'nohup.out',\n",
       " '.mplayer',\n",
       " '.thunderbird',\n",
       " 'TFbook',\n",
       " 'wujinjun_py',\n",
       " 'Documents']"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.listdir(\"/home/wjj\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
